package com.lanou.sinasports;


import android.database.sqlite.SQLiteDatabase;
import android.support.v4.app.FragmentManager;

import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TabHost;


import com.lanou.sinasports.adapter.DrawAdapter;
import com.lanou.sinasports.dao.DaoMaster;
import com.lanou.sinasports.dao.DaoSession;
import com.lanou.sinasports.dao.Dog;
import com.lanou.sinasports.dao.DogDao;
import com.lanou.sinasports.fragment.MatchFragment;
import com.lanou.sinasports.fragment.NewsFragment;
import com.lanou.sinasports.fragment.SpecialFragment;
import com.lanou.sinasports.fragment.TeamFragment;
import com.mob.tools.utils.UIHandler;

import java.util.List;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.onekeyshare.OnekeyShare;

public class MainActivity extends AppCompatActivity  implements MatchFragment.ControlActivity{
    private TabHost tabHost;
    private FragmentManager fm;
    private DrawerLayout drawerLayout;
    private ListView listView;
    private DrawAdapter adapter;
    private ImageView imageView;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        imageView= (ImageView) findViewById(R.id.iv_weibo_logo);


        tabHost= (TabHost) findViewById(android.R.id.tabhost);
        tabHost.setup();

        TabHost.TabSpec tab1=tabHost.newTabSpec("tab1");
        View view1=getLayoutInflater().inflate(R.layout.view1,null);
        tab1.setIndicator(view1);
        tab1.setContent(R.id.tab1);
        tabHost.addTab(tab1);

        TabHost.TabSpec  tab2=tabHost.newTabSpec("tab2");
        View view2=getLayoutInflater().inflate(R.layout.view2,null);
        tab2.setIndicator(view2);
        tab2.setContent(R.id.tab2);
        tabHost.addTab(tab2);

        TabHost.TabSpec  tab3=tabHost.newTabSpec("tab3");
        View view3=getLayoutInflater().inflate(R.layout.view3,null);
        tab3.setIndicator(view3);
        tab3.setContent(R.id.tab3);
        tabHost.addTab(tab3);

        TabHost.TabSpec  tab4=tabHost.newTabSpec("tab4");
        View view4=getLayoutInflater().inflate(R.layout.view4,null);
        tab4.setIndicator(view4);
        tab4.setContent(R.id.tab4);
        tabHost.addTab(tab4);

        fm=getSupportFragmentManager();
        android.support.v4.app.FragmentTransaction transaction=fm.beginTransaction();

        transaction.replace(R.id.tab1, new MatchFragment());
        transaction.replace(R.id.tab2, new NewsFragment());
        transaction.replace(R.id.tab3, new SpecialFragment());
        transaction.replace(R.id.tab4, new TeamFragment());

        transaction.commit();

        drawerLayout= (DrawerLayout) findViewById(R.id.dl_main);
        listView= (ListView) findViewById(R.id.lv_drawer);
        adapter=new DrawAdapter(this);
        listView.setAdapter(adapter);

//        DaoMaster.DevOpenHelper helper=new DaoMaster.DevOpenHelper(this,"test.db",null);
//        SQLiteDatabase db=helper.getWritableDatabase();
//        DaoMaster master=new DaoMaster(db);
//        DaoSession session=master.newSession();
//        DogDao dogDao=session.getDogDao();
//
//        Dog dog=new Dog();
//        dog.setType("狼狗");
//        dogDao.insert(dog);

        //dogDao.queryBuilder().list(); 查询所有数据

        /**
         * 推送git
         * git add .
         * git commit -m "xx"
         * git push origin master
         */

        /** 往fragment传值
        Bundle args=new Bundle();
        args.putInt(position,pption);
        fragment.setArguments(args);
         */

        /**
         * 导包:greenrobot 3.0.0
         * activity:
         * 触发谁在谁那里 注册：
         * EventBus.getDefault().register(this)
         *
         * @subscribe
         * public void onEvent(){}
         *
         *
         * fragment
         * //发送事件
         * EventBus.getDefault.post(); 参数为传的值
         */

    }





    @Override
    public void control() {
         drawerLayout.openDrawer(Gravity.LEFT);
    }




}
